<?php

class Application_Model_DbTable_Actionlog extends Zend_Db_Table_Abstract
{

    protected $_name = 'action_log';
    public function addActionLog($log_id,$description){

           $timeStamp = mktime(date('H'),date('i'), date('s')
                            ,date('m'),date('d'),date('y'));
           $dob_disp1=strftime('%Y-%m-%d %H:%M:%S',$timeStamp);
             $data=array(
                 'log_id'=>$log_id,
                 'description'=>$description,
                 'time'=>$dob_disp1
             );
             $this->insert($data);
 //            return $this->getAdapter()->lastInsertId('log');
    }
    //Function to display log
    public function getLog(){
        $sqlQuery="select a.time,a.description as action,c.username,d.name as role
                   from Action_log a,  Log b, Admin c, Role d where
                   a.log_id = b.log_id and b.admin_id = c.admin_id
                   and c.role_id = d.role_id order by a.time desc ";
      $db=$this->getAdapter();
      $stmt = $db-> query($sqlQuery);
      $row = $stmt->fetchAll();
      return $row;
    }
    public function getDateLog($date){

          list($y, $m, $d) = explode('-', $date);
          
          $mk=mktime(0, 0, 0, $m, $d, $y);
          $date1=strftime('%Y-%m-%d 00:00:00',$mk);
          //$mk2=mktime(0, 0, 0, $m, $d+1, $y);
          $mk2 = $mk + (24*60*60);
          $date2=strftime('%Y-%m-%d 00:00:00',$mk2);
          
        $sqlQuery="select a.time,a.description as action,c.username,d.name as role
                   from Action_log a,  Log b, Admin c, Role d where
                   a.log_id = b.log_id and b.admin_id = c.admin_id
                   and c.role_id = d.role_id and a.time >='".$date1."'
                   and a.time < '".$date2."' order by a.time desc ";
  
      $db=$this->getAdapter();
      $stmt = $db-> query($sqlQuery);
      $row = $stmt->fetchAll();
      return $row;
    }
}

